﻿@inject IStringLocalizer<DrawerNormal> Localizer

<div>
    <p class="d-flex flex-wrap drawer-demo">
        <RadioList TValue="SelectedItem" Items="@DrawerDirection" OnSelectedChanged="@OnStateChanged" />
    </p>
    <p>
        <button type="button" class="btn btn-primary" @onclick="@(e => IsOpen = true)">@Localizer["Open"]</button>
    </p>
    <Drawer Placement="@DrawerAlign" IsOpen="@IsOpen">
        <div class="d-flex justify-content-center align-items-center flex-column" style="height: 290px;">
            <p>@Localizer["Description"]</p>
            <button type="button" class="btn btn-primary" @onclick="@(e => IsOpen = false)">@Localizer["Close"]</button>
        </div>
    </Drawer>
</div>

@code {
    private bool IsOpen { get; set; }

    private Placement DrawerAlign { get; set; }

    private IEnumerable<SelectedItem> DrawerDirection { get; } = new SelectedItem[]
    {
        new SelectedItem("left", "left to right")
        {
            Active = true
        },
        new SelectedItem("right", "right to left"),
        new SelectedItem("top", "top to bottom"),
        new SelectedItem("bottom", "bottom to top")
    };

    private Task OnStateChanged(IEnumerable<SelectedItem> values, SelectedItem val)
    {
        DrawerAlign = val.Value switch
        {
            "right" => Placement.Right,
            "top" => Placement.Top,
            "bottom" => Placement.Bottom,
            _ => Placement.Left
        };
        IsOpen = false;
        StateHasChanged();
        return Task.CompletedTask;
    }
}
